package com.gxa.web_admin.controller.lnz;

import cn.hutool.core.bean.BeanUtil;
import com.gxa.common.base.RespResult;
import com.gxa.modules.dto.AdvancedContractDTO;
import com.gxa.modules.dto.ContractDTO;
import com.gxa.modules.dto.RenewalRecordDTO;
import com.gxa.modules.entity.CrmContractType;
import com.gxa.modules.service.ContractService;
import com.gxa.web_admin.vo.AdvancedContractVO;
import com.gxa.web_admin.vo.ContractVO;
import com.gxa.web_admin.vo.RenewalRecordVO;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("/contract")
public class ContractController {

    @Autowired
    private ContractService contractService;

    /**
     * 查询所有合同列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/queryAllContracts",method = RequestMethod.GET)
    public RespResult queryAllContracts(int currentPage, int pageSize){
        return contractService.queryAllContractsByPage(currentPage,pageSize);
    }

    /**
     * 查询今日新增的合同列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/queryContractsByToday",method = RequestMethod.GET)
    public RespResult queryContractsByToday(int currentPage,int pageSize){
        return contractService.queryContractsByTodayByPage(currentPage,pageSize);
    }

    /**
     * 查询本周新增的合同列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/queryContractsByWeek",method = RequestMethod.GET)
    public RespResult queryContractsByWeek(int currentPage,int pageSize){
        return contractService.queryContractsByWeekByPage(currentPage,pageSize);
    }

    /**
     * 查询本月新增的合同列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/queryContractsByMonth",method = RequestMethod.GET)
    public RespResult queryContractsByMonth(int currentPage,int pageSize){
        return contractService.queryContractsByMonthByPage(currentPage,pageSize);
    }

    /**
     * 查询今日到期的合同列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/queryContractsByDueToday",method = RequestMethod.GET)
    public RespResult queryContractsByDueToday(int currentPage,int pageSize){
        return contractService.queryContractsByDueTodayByPage(currentPage,pageSize);
    }

    /**
     * 查询本周到期的合同列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/queryContractsByDueWeek",method = RequestMethod.GET)
    public RespResult queryContractsByDueWeek(int currentPage,int pageSize){
        return contractService.queryContractsByDueWeekByPage(currentPage,pageSize);
    }

    /**
     * 查询本月到期的合同列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/queryContractsByDueMonth",method = RequestMethod.GET)
    public RespResult queryContractsByDueMonth(int currentPage,int pageSize){
        return contractService.queryContractsByDueMonthByPage(currentPage,pageSize);
    }

    /**
     * 新增合同
     * @param contractVO
     * @return
     */
    @RequestMapping(value = "/addContract",method = RequestMethod.POST)
    public RespResult addContract(@RequestBody ContractVO contractVO){
        ContractDTO contractDTO = BeanUtil.copyProperties(contractVO, ContractDTO.class);
        return contractService.insertContract(contractDTO);
    }

    /**
     * 新增合同类型
     * @param crmContractType
     * @return
     */
    @RequestMapping(value = "/addContractType",method = RequestMethod.POST)
    public RespResult addContractType(@RequestBody CrmContractType crmContractType){
        return contractService.insertContractType(crmContractType);
    }

    /**
     * 查询合同类型
     * @return
     */
    @RequestMapping(value = "/queryContractTypes",method = RequestMethod.GET)
    public RespResult queryContractTypes(){
        return contractService.selectContractTypes();
    }

    /**
     * 修改合同类型
     * @param crmContractType
     * @return
     */
    @RequestMapping(value = "/updateContractType",method = RequestMethod.POST)
    public RespResult updateContractType(@RequestBody CrmContractType crmContractType){
        return contractService.reviseContractType(crmContractType);
    }

    /**
     * 删除合同类型
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteContractType",method = RequestMethod.POST)
    public RespResult deleteContractType(int id){
        return contractService.deleteContractType(id);
    }

    /**
     * 新增合同续费记录
     * @param renewalRecordVO
     * @return
     */
    @RequestMapping(value = "/addRenewal",method = RequestMethod.POST)
    public RespResult addRenewal(@RequestBody RenewalRecordVO renewalRecordVO){
        RenewalRecordDTO renewalRecordDTO = BeanUtil.copyProperties(renewalRecordVO, RenewalRecordDTO.class);
        return contractService.addRenewal(renewalRecordDTO);
    }

    /**
     * 修改合同续费记录
     * @param renewalRecordVO
     * @return
     */
    @RequestMapping(value = "/updateRenewal",method = RequestMethod.POST)
    public RespResult updateRenewal(@RequestBody RenewalRecordVO renewalRecordVO){
        RenewalRecordDTO renewalRecordDTO = BeanUtil.copyProperties(renewalRecordVO, RenewalRecordDTO.class);
        return contractService.updateRenewal(renewalRecordDTO);
    }

    /**
     * 删除合同续费记录
     * @param id
     * @return
     */
    @RequestMapping(value = "/deleteRenewal",method = RequestMethod.POST)
    public RespResult deleteRenewal(int id){
        return contractService.deleteRenewal(id);
    }

    /**
     * 修改续费状态
     * @param id
     * @param status
     * @return
     */
    @RequestMapping(value = "/updateRenewalStatus",method = RequestMethod.POST)
    public RespResult updateRenewalStatus(int id,String status){
        return contractService.updateRenewalStatus(id,status);
    }

    /**
     * 查询合同对应的续费记录
     * @param contractId
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/queryRenewals",method = RequestMethod.GET)
    public RespResult queryRenewals(String contractId,int currentPage,int pageSize){
        return contractService.queryRenewals(contractId,currentPage,pageSize);
    }

    /**
     * 到款
     * @param contractId
     * @param payment
     * @param remark
     * @return
     */
    @RequestMapping(value = "/paymentReceived",method = RequestMethod.POST)
    public RespResult paymentReceived(String contractId,BigDecimal payment,String remark){
        return contractService.paymentReceived(contractId,payment,remark);
    }

    /**
     * 修改合同
     * @param contractVO
     * @return
     */
    @RequestMapping(value = "/updateContract",method = RequestMethod.POST)
    public RespResult updateContract(@RequestBody ContractVO contractVO){
        ContractDTO contractDTO = BeanUtil.copyProperties(contractVO, ContractDTO.class);
        return contractService.updateContract(contractDTO);
    }

    /**
     * 删除合同
     * @param contractId
     * @return
     */
    @RequestMapping(value = "/deleteContract",method = RequestMethod.POST)
    public RespResult deleteContract(String contractId){
        return contractService.deleteContract(contractId);
    }

    /**
     * 修改合同状态
     * @param contractId
     * @param status
     * @param auditorId
     * @return
     */
    @RequestMapping(value = "/updateContractStatus",method = RequestMethod.POST)
    public RespResult updateContractStatus(String contractId,String status,int auditorId){
        return contractService.updateContractStatus(contractId,status,auditorId);
    }

    /**
     * 按条件（客户名称、合同编号）搜索合同列表
     * @param condition
     * @return
     */
    @RequestMapping(value = "/queryContractByCondition",method = RequestMethod.GET)
    public RespResult queryContractByCondition(String condition){
        return contractService.queryContractByCondition(condition);
    }

    /**
     * 高级搜索合同列表
     * @param advancedContractVO
     * @param currentPage
     * @param pageSize
     * @return
     */
    @RequestMapping(value = "/advancedQueryContracts",method = RequestMethod.GET)
    public RespResult advancedQueryContracts(AdvancedContractVO advancedContractVO, int currentPage, int pageSize){
        AdvancedContractDTO advancedContractDTO = BeanUtil.copyProperties(advancedContractVO, AdvancedContractDTO.class);
        return null;
    }

}
